package com.xzq.action;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;

import com.xzq.biz.AddressBiz;
import com.xzq.biz.ONPBiz;
import com.xzq.biz.OrdersBiz;
import com.xzq.entity.Address;
import com.xzq.entity.OrderAndProduct;
import com.xzq.entity.Orders;
import com.xzq.entity.User;

@Controller
public class OrdersAction extends BaseAction {
	@Resource
	private OrdersBiz biz;
	@Resource
	private AddressBiz abiz;
	private Orders orders1;
	private Orders orders;
	private Orders changeOrder;
	private List<Address> addresses;
	private Double sum;
	
	public Orders getChangeOrder() {
		return changeOrder;
	}
	public void setChangeOrder(Orders changeOrder) {
		this.changeOrder = changeOrder;
	}
	public List<Address> getAddresses() {
		return addresses;
	}
	public void setAddresses(List<Address> addresses) {
		this.addresses = addresses;
	}
	public Double getSum() {
		return sum;
	}
	public void setSum(Double sum) {
		this.sum = sum;
	}
	public Orders getOrders() {
		return orders;
	}
	public void setOrders(Orders orders) {
		this.orders = orders;
	}
	
	
	
	public Orders getOrders1() {
		return orders1;
	}
	public void setOrders1(Orders orders1) {
		this.orders1 = orders1;
	}
	public String toShopCat(){
		User user = (User) session.get("user");
		addresses = abiz.findOneUserAllAddress(user);
		orders1 = biz.findISHaveShopCat(user);
		orders = new Orders();
		orders.setId(orders1.getId());
		orders = biz.findOneOrder(orders);
		sum = biz.findSumPrice(orders);
		return "shopcat";
	}
	
	public String changeOrder(){
		User user = (User) session.get("user");
		Address a = changeOrder.getAddress();
		a = abiz.findOneAddress(a);
		changeOrder = biz.findOneOrder(changeOrder);
		changeOrder.setAddress(a);
		int count = biz.modifyOrders(changeOrder);
		if(count==1){
			int count2 = biz.modifyOrdersByShopCatToOrders(user);
			if(count2==1){
				return "index";
			}
		}
		return "fail";
	}
}
